package com.mchat.web.controller;


import com.mchat.communication.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@Controller
public class IndexController {
    @Resource
    private UserService userService;

    @RequestMapping("/")
    public String login() {
        return "index/login";
    }

    @RequestMapping("login")
    public String login(HttpServletRequest request, Model model) {
        chat(request, model);
        return "index/login";
    }

    @RequestMapping("chat")
    public String chat(HttpServletRequest request, Model model) {
        String username = request.getParameter("username");
        if (StringUtils.isEmpty(username)) {
            return "index/login";
        }
        model.addAttribute("username", username);
        return "index/chat";
    }

    @GetMapping("/test")
    @ResponseBody
    public Object test() {
        return userService.getUserSeqByUserName("geticsen");
    }

}
